#!/usr/bin/env python 

import main
import unittest

class TestMainProjectFunction(unittest.TestCase): 
  def setUp(self): 
    self.files = ["gene1.fasta", "gene2.fasta", "gene3.gb"]  

  def test_read_function(self): 
    seqs_names, _ = main.read_sequences(self.files) 
    mark = set()
    for name in seqs_names: 
      self.assertTrue(not (name in mark))
      mark.add(name)    

  def test_gc_content_function(self): 
    seqs_name, seqs = main.read_sequences(self.files) 
    gc_values = main.compute_GC(seqs_name, seqs)
    for val in gc_values: 
      self.assertTrue(0 <= val <= 100)
      
  def test_transcription_function(self): 
    def create_rna(in_str): 
      out_str = "" 
      for s in in_str: 
        if s == 'T': 
          out_str += 'U'
        else: 
          out_str += s
      return out_str
    seqs_name, seqs = main.read_sequences(self.files) 
    rna_seqs = main.transcription(seqs_name, seqs) 
   
    my_rna_seqs = []
    for seq in seqs: 
      my_rna_seqs.append(create_rna(seq))

    self.assertTrue(len(rna_seqs) == len(my_rna_seqs))

    for i in range(len(rna_seqs)): 
      self.assertEqual(str(rna_seqs[i]), my_rna_seqs[i])
    
  def test_translation_function(self):
    seqs_name, seqs = main.read_sequences(self.files) 
    rna_seqs = main.transcription(seqs_name, seqs) 
    prt_seqs = main.translation(seqs_name, seqs) 
    self.assertEqual(len(rna_seqs), len(prt_seqs))

if __name__ == '__main__': 
  unittest.TextTestRunner(verbosity=2).run(unittest.TestLoader().loadTestsFromTestCase(TestMainProjectFunction))
